<?php
header("content-type:text/html;charset=utf-8");

session_start();                            //开启session

if(isset($_SESSION["u_user"])) {              //判断是否设置session
    if($_SESSION["u_user"]=='admin') {        //设置了session，判断用户
	    header("location:/work/admin.php?id=".$_SESSION["u_id"]."");
	} else {
		header("location:/work/time.php?id=".$_SESSION["u_id"]."");
	}
} 
else {                                    //没有设置session，开启登陆验证
    if(isset($_POST['submit'])) {
	    include_once ('classes/user/user.class.php');
        $user = new user();
		$res = $user->check_user($_POST['username'],$_POST['password']);
		switch($res) {
		    case 'admin':
                $user->add_session($_POST['username']);
			    $info = $user->get_one_user($_POST['username'],$field='u_user');
		        header("location:/work/admin.php?id=".$info['u_id']."");
				break;
			case 'no':
                echo '<script>alert("账号密码错误，请核对后重新输入");location.href="login1.php";</script>'; 
                break;
			default:
				echo '<script>alert("未知错误");location.href="login1.php";</script>';
		}
	}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>加班管理系统</title>
    <link rel="stylesheet" type="text/css" href="css/styles.css">
    <!--[if IE]>
    <script src="http://libs.baidu.com/html5shiv/3.7/html5shiv.min.js"></script>
    <![endif]-->
</head>
<body>
<div class="container" style="padding-top:100px">
    <div class="login-wrap">
        <div class="login-html">
            <input id="tab-1" type="radio" name="tab" class="sign-in" checked><label for="tab-1" class="tab">管理员登录</label>
            <div class="login-form">
			<form id="form" name="form" method="post" class="padder" action="login1.php" >
                    <div class="sign-in-html">
                        <div class="group">
                            <label for="user" class="label">用户名</label>
                            <input id="username" name="username" type="text" class="input">
                        </div>
                        <div class="group">
                            <label for="password" class="label">密码</label>
                            <input id="password" type="password" name="password" class="input" data-type="password">
                        </div>
                        <div class="group">
                            <input id="check" type="checkbox" class="check" checked>
                            <label for="check"><span class="icon"></span>记住登录?</label>
                        </div>
                        <div class="group">
                                <button type="submit" name="submit" id="submit" class="button" >登录</button>
                            </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>

</body>
</html>